/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Util.ConSQL;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author use
 */
public class Dangnhap {
    ConSQL conn = new ConSQL();
    public boolean kiemtraUser(String user) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select userName  from account where userName ='"+user+"';");
        if (rs.next()) return true;
        return false;
    }
    public boolean kiemtraPass(String pass,String tendangnhap) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select pass from account where pass='"+pass+"';");
        if (rs.next()) return true;
        return false;
    }
    public String layQuyenhang(String user) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select quyenHan  from account where userName='"+user+"';");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
      
    }
    public String laytenSV(String MaSV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select hoTen from sinhVien where maSV='"+MaSV+"'");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }      
    public String laymaSV(String MaSV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select maSV from sinhVien where maSV='"+MaSV+"'");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }      
    public String layTenGV(String maGV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select tenGV from giaoVien where maGV='"+maGV+"'");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }
    public String laymaGV(String maGV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select maGV from giaoVien where maGV='"+maGV+"'");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }
    public String laytenLopSH(String MaSV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select tenlopSH  from sinhVien,lopSH where maSV='"+MaSV+"' and lopSH.malopSH=sinhVien.malopSH;");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }        
    public String laytenNK(String MaSV) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select tenNK from sinhVien,nienKhoa,lopSH where maSV='"+MaSV+"' and lopSH.malopSH=sinhVien.malopSH and LopSH.maNK=nienKhoa.maNK;");
        if (rs.next()) return rs.getString(1);
        else return rs.getString(1);
    }
    public String laytenphongban(String tenPB) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select tenPb from phongBan where maPB='"+tenPB+"'");
        if(rs.next()){
            return rs.getString(1);
        }
        return rs.getString(1);
    }
    public String laymaphongban(String mapb) throws Exception{
        Statement st = conn.getCon().createStatement();
        ResultSet rs = st.executeQuery("select maPB from phongBan where maPB='"+mapb+"'");
        if(rs.next()){
            return rs.getString(1);
        }
        return rs.getString(1);
    }
}
